<template>
  <div>
    <el-row>
      <el-col :span="3" :offset="2">
        <el-tabs :stretch="true" v-model="activeName" type="card" @tab-click="handleClick">
          <el-tab-pane label="社保" name="2"></el-tab-pane>
          <el-tab-pane label="医保" name="1"></el-tab-pane>
        </el-tabs>
      </el-col>
      <el-col :span="4" :offset="15">
        <!-- <el-button size="small" plain type="success" style="width:100px;" @click="createManage">新建</el-button> -->
      </el-col>
    </el-row>
    <el-row>
      <el-col :offset="2" :span="10">
        <el-radio-group v-model="systemCode" @change="sysTemChange">
          <el-radio :label="item.code" v-for="item of systemNameOptions" :key="item.code">{{item.name}}</el-radio>
        </el-radio-group>
      </el-col>
    </el-row>
    <el-table :data="tableData" style="width: 100%;margin-top:20px;">
      <el-table-column align="center" label="系统名称" prop="systemName"></el-table-column>
      <!-- <el-table-column align="center" label="流程ID" prop="procedefId"></el-table-column> -->
      <el-table-column align="center" label="事项名称" prop="name"></el-table-column>
      <el-table-column align="center" label="事项ID" prop="id"></el-table-column>
      <!-- <el-table-column align="center" label="流程名称" prop="procedefName"></el-table-column> -->
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <!-- <el-button size="small" type="primary" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>-->
          <el-button size="small" type="primary" @click="detailsClick(scope.$index, scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page" v-show="false">
      <el-pagination
        @current-change="pageChange"
        :page-size="pageSize"
        layout="prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
const PAGESIZE = 1000;
export default {
  data() {
    return {
      tableData: [],
      total: 1000,
      pageSize: 1000,
      isShowTable: false,
      activeName: "2",
      systemName: "01",
      systemCode:"01",
      systemNameOptions: [],
      type: "2"
    };
  },
  created() {
    this.init(this.type,this.systemCode);
  },
  methods: {
    init(type,systemCode) {
      this.$post("/proceeding/list", {
        pageNum: 1,
        pageSize: PAGESIZE,
        systemCode: systemCode,
        hasInited: 1,
      }).then(data => {
        this.tableData = data.result.dataList;
      });
      // 获取系统列表
      this.$get("/system/wfSystemList", {
        type: type,
        pageNum: 1,
        pageSize: 1000
      }).then(data => {
        if (data.data.success) {
          this.systemNameOptions = data.data.result.dataList;
        }
      });
    },
    // handleEdit(index, row) {
    //   this.$router.push({
    //     path: "/home/itemConfig",
    //     query: {
    //       sysName: this.systemName,
    //       itemId: row.id,
    //       type: "edit",
    //       itemName: row.name,
    //       InsuranceName: this.activeName
    //     }
    //   });
    // },
    sysTemChange(val) {
      this.init(this.type,this.systemCode);
      // this.systemName = val.code;
    },
    handleClick(tab, event) {
      this.type = tab.name;
      
      if (tab.label == "医保") {
        // this.tableData = [];
      }
      if (tab.label == "社保") {
         this.systemCode="01"
      }
      this.init(this.type,this.systemCode);
    },
    detailsClick(index, row) {
      this.$router.push({
        path: "/home/KeyManage",
        query: {
          sysName: this.activeName,
          itemId: row.id,
          procedefId:row.procedefId,
          systemCode:row.systemCode
        }
      });
    },
    handleDelete(index, row) {
      this.$confirm("确认删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$post("/proceeding/delete", {
            id: row.id
          }).then(data => {
            this.tableData.splice(index, 1);
            this.$message({
              type: "success",
              message: data.resultDes
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    createManage() {
      this.$router.push({
        path: "/home/KeyManage",
        query: {
          type: "add",
          sysName: this.systemCode,
          InsuranceName: this.activeName
        }
      });
    },
    pageChange(val) {
      this.init();
    }
  }
};
</script>

<style scoped lang="css">
.page {
  /* display: flex; */
  width: 100%;
  /* justify-content: center; */
  position: fixed;
  bottom: 100px;
  /* text-align: center; */
  /* right: 200px; */
}
</style>
